subroutine inputVector(name,nCells,U)
implicit none
    character (*) name
    character *280 a
    integer nCells
    real *8 U(3,nCells)
    integer i,j,jj, OpenFile
    
    open(11,file=name,IOSTAT=OpenFile)
    if (OpenFile.ne.0) then
	    write(*,*) 'Fatal Error: File open error '//name
    end if
    
    do i=1,22
        read(11,*)
    end do
    do i=1,nCells
        read(11,'(a280)') a
        do j=1,100
            if (a(j:j).eq.')') a(j:j)=' '
            if (a(j:j).eq.'(') a(j:j)=' '
        end do
        read(a,*) (U(jj,i),jj=1,3)
    end do
    
    close(11)
    return
end subroutine inputVector

subroutine inputScalar(name,nCells,U,CurrentTime,nStepInitial,TimeStepInitial)
implicit none
    character(*),intent(in) :: name
    integer,intent(in) :: nCells
    real(8),intent(out) :: U(nCells)
    real(8),intent(out) :: CurrentTime
    integer,intent(out) :: nStepInitial
    real(8),intent(out) :: TimeStepInitial
    
    
    character *280 :: auxS,auxS1,auxS2,auxS3,auxS4
    integer :: i, OpenFile
    integer :: nCellsRead
    
    open(11,file=name,IOSTAT=OpenFile)
    if (OpenFile.ne.0) then
	    write(*,*) 'Fatal Error: File open error '//name
	    return
    end if

    read(11,*)
    
!    if(present(CurrentTime)) then
        read(11,*) auxS,auxS1, CurrentTime ! Sorry, I can't write more nicer, VSemiletov
!    else
!        read(11,*)
!    end if
!    if(present(nStepInitial)) then
        read(11,*) auxS,auxS1,auxS2,auxS3,auxS4, nStepInitial ! Sorry, I can't write more nicer, VSemiletov
!    else
!        read(11,*)
!    end if
!    if(present(TimeStepInitial)) then
        read(11,*) auxS,auxS1,auxS2,auxS3,auxS4, TimeStepInitial ! Sorry, I can't write more nicer, VSemiletov
!    else
!        read(11,*)
!    end if
    
    read(11,*) auxS,auxS1, nCellsRead
    if(nCells.ne.nCellsRead)then
        write(*,*) 'Dimension of input array is not correspond with grid. ', name
        return
    end if
    
    do i=6,22
        read(11,*)
    end do
    
    do i=1,nCells
        read(11,*) U(i)
    end do
    
    close(11)
    return
end subroutine inputScalar

subroutine  ReadRestartBin(name, &
                            CurrentTime,nStepInitial,TimeStepInitial, &
                            nCells,nFaces, &
                            U,p,T, &
                            Usnew,Psnew,Rhosnew, &
                            utmp) !, inputRestart)
implicit none
    character(*),intent(in) :: name
    real(8),intent(inout) :: CurrentTime
    integer,intent(inout) :: nStepInitial
    real(8),intent(inout) :: TimeStepInitial
    integer,intent(in) :: nCells,nFaces
    real(8),intent(out) :: U(3,nCells),p(nCells),T(nCells)
    real(8),intent(out) :: Usnew(3,nFaces),Psnew(nFaces),Rhosnew(nFaces)
    real(8),intent(out) :: utmp(800)
    
    integer :: inputRestart
    integer :: i
    integer :: nBeginCell,nCellsRead, nBeginFace,nFacesRead
    integer :: OpenFile
    integer :: ierr

    write(*,*) name, ' begin to read restarts!'

    inputRestart = 31
    open(inputRestart,file=name,form='unformatted',IOSTAT=OpenFile) !)
    !open(11,file=name,form='unformatted',IOSTAT=OpenFile) !)
    
    
    if (OpenFile.ne.0) then
	    write(*,*) 'Fatal Error: File open error '//name
	    return
    end if
    
    read(inputRestart,iostat=ierr) CurrentTime, nStepInitial, TimeStepInitial
 	if(ierr.ne.0)then
 	    STOP '@@ FATAL ERROR in restart reading!'
 	end if

 	read(inputRestart,iostat=ierr) nBeginCell,nCellsRead, nBeginFace,nFacesRead
 	if(ierr.ne.0)then
 	    STOP '@@ FATAL ERROR in restart reading!'
 	end if

 	if(nCells.ne.(nCellsRead-nBeginCell+1).or.nFaces.ne.(nFacesRead-nBeginFace+1))then
 	    write(*,*)
 	    write(*,*) 'Fatal error: ', name, ' nCells or nFaces of Grid is not equal with nCells or nFaces of Restarts'
 	    write(*,*) 'nCells=', nCells, nCellsRead-nBeginCell+1, ' nFaces=', nFaces,nFacesRead-nBeginFace+1
 	    write(*,*)
 	    return
 	end if
 	
 	read(inputRestart,iostat=ierr) (U(1:3,i),p(i),T(i),i=1,nCells)
 	if(ierr.ne.0)then
 	    STOP '@@ FATAL ERROR in restart reading!'
 	end if

 	read(inputRestart,iostat=ierr) (Usnew(1:3,i),psnew(i),Rhosnew(i),i=1,nFaces)
 	if(ierr.ne.0)then
 	    STOP '@@ FATAL ERROR in restart reading!'
 	end if

 	read(inputRestart,iostat=ierr) (utmp(i),i=1,800)
 	if(ierr.ne.0)then
 	    STOP '@@ FATAL ERROR in restart reading!'
 	end if

 	write(*,*) 'CurrentT=',CurrentTime,'nStepInit=',nStepInitial,'TStepInit=',TimeStepInitial

    write(*,*) name, ' end to read restarts successfully!'

    close(inputRestart) !11)
    return
end subroutine  ReadRestartBin